# include <bits/stdc++.h>
# define MAXN 1000023
using namespace std;
# define getchar readc 
char buf[1 << 18], *fs, *ft;
inline char readc() {
	return (fs == ft && (ft =(fs = buf) + fread(buf, 1, 1<<18, stdin)), fs == ft) ? EOF : *fs++;
}
inline int gn() {
	int k = 0, f = 1;
	char c = getchar();
	for(;!isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
	return k * f;
}
int a[MAXN], mx[MAXN << 2], mi[MAXN << 2], M, n, k;
inline void push_up(int x) {
	mx[x] = max(mx[x << 1], mx[x << 1 | 1]);
	mi[x] = min(mi[x << 1], mi[x << 1 | 1]);
}
inline void build() {
	for(M = 1; M <= n + 1; M <<= 1);
	for(int i = 1; i <= n; i++) {
		mx[M + i] = mi[M + i] = a[i];
	}
	for(int i = M; i >= 1; i--) {
		push_up(i);
	}
}
inline int query_max(int l, int r) {
	int tmp = mi[1];
	for(l += M - 1, r += M + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
		if(~l & 1) tmp = max(mx[l + 1], tmp);
		if(r & 1) tmp = max(mx[r - 1], tmp);
	}
	return tmp;
}
inline int query_min(int l, int r) {
	int tmp = mx[1];
	for(l += M - 1, r += M + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
		if(~l & 1) tmp = min(mi[l + 1], tmp);
		if(r & 1) tmp = min(mi[r - 1], tmp);
	}
	return tmp;
}


int main() {
	freopen("window.in", "r", stdin);
	freopen("window.out", "w", stdout);
	n = gn();
	k = gn();
	for(int i = 1; i <= n; i++) a[i] = gn();
	build();
	//printf("-1");
	for(int i = 1; i + k - 1 <= n; i++) {
		printf("%d ", query_min(i, i + k - 1));
	}
	printf("\n");
	for(int i = 1; i + k - 1 <= n; i++) {
		printf("%d ", query_max(i, i + k - 1));
	}
	return 0;
}

